import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.Handler;
import java.util.logging.FileHandler;
import java.util.logging.Formatter;
import java.util.logging.SimpleFormatter;

public class FormatterExample {

  private static final Logger LOGGER = Logger.getLogger(FormatterExample.class.getName());

  public static void main(String[] args) {

    Handler fileHandler = null;
    Formatter simpleFormatter = null;

    try {
      // Creating FileHandler.
      fileHandler = new FileHandler("./test.log");

      // Creating SimpleFormatter.
      simpleFormatter = new SimpleFormatter();

      // Assigning handler to logger.
      LOGGER.addHandler(fileHandler);

      LOGGER.info("Finnest message: Logger with DEFAULT FORMATTER");

      fileHandler.setFormatter(simpleFormatter);

      fileHandler.setLevel(Level.ALL);
      LOGGER.setLevel(Level.ALL);
      LOGGER.finest("Finnest message: Logger with SIMPLE FORMATTER");
    } catch (IOException ex) {
      LOGGER.log(Level.SEVERE, "Error occur in FileHandler.", ex);
    }
  }

}
